/**
 * Copyright (c) Sinosoft Co.,LTD.
 * All right reserved.
 */

package com.sinosoft.lis.schema;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.Date;

import cn.zxd.util.*;
import com.sinosoft.lis.db.T_UserDB;

/**
 * <p>ClassName: T_UserSchema </p>
 * <p>Description: DB层 Schema 类文件 </p>
 * <p>Company: Sinosoft Co.,LTD </p>
 * @Database: PhysicalDataModel_1
 * @author：Makerx
 * @CreateDate：2017-09-01
 */
public class T_UserSchema implements Schema, Cloneable
{
    // @Field
    /** 用户登录ID */
    private String User_Code;
    /** 组织机构ID */
    private String Organ_Id;
    /** 用户密码 */
    private String PassWord;
    /** 真实姓名 */
    private String Real_Name;
    /** 用户类型 */
    private String Type_Id;
    /** 性别 */
    private String Sex;
    /** 用户状态 */
    private String Status_Id;
    /** 联系方式 */
    private String Tel;

    /** 日期处理 */
    private FDate fDate = new FDate(); 
    /** 创建日期 */
    private Date Create_Date;
    /** 操作时间 */
    private Date Insert_Time;
    /** 更新时间 */
    private Date Update_Time;
    /** 操作员 */
    private String Operator;

    /** 数据库表的字段个数 */
    public static final int FIELDNUM = 12; 

    /** 主键 */
    private static String[] PK; 

    /** 错误信息 */
    public CErrors mErrors; 

    // @Constructor
    public T_UserSchema()
    {
        mErrors = new CErrors();
        String[] pk = new String[1];
        pk[0] = "User_Code";
        PK = pk;
    }

    /**
     * Schema克隆
     * @return Object
     * @throws CloneNotSupportedException
     */
    public Object clone() throws CloneNotSupportedException
    {
        T_UserSchema cloned = (T_UserSchema)super.clone();
        cloned.fDate = (FDate) fDate.clone();
        cloned.mErrors = (CErrors) mErrors.clone();
        return cloned;
    }

    // @Method
    public String[] getPK()
    {
        return PK;
    }

    public String getUser_Code()
    {
        return User_Code;
    }

    public void setUser_Code(String aUser_Code)
    {
        User_Code = StrTool.cTrim(aUser_Code);
    }

    public String getOrgan_Id()
    {
        return Organ_Id;
    }

    public void setOrgan_Id(String aOrgan_Id)
    {
        Organ_Id = StrTool.cTrim(aOrgan_Id);
    }

    public String getPassWord()
    {
        return PassWord;
    }

    public void setPassWord(String aPassWord)
    {
        PassWord = StrTool.cTrim(aPassWord);
    }

    public String getReal_Name()
    {
        return Real_Name;
    }

    public void setReal_Name(String aReal_Name)
    {
        Real_Name = StrTool.cTrim(aReal_Name);
    }

    public String getType_Id()
    {
        return Type_Id;
    }

    public void setType_Id(String aType_Id)
    {
        Type_Id = StrTool.cTrim(aType_Id);
    }

    public String getSex()
    {
        return Sex;
    }

    public void setSex(String aSex)
    {
        Sex = StrTool.cTrim(aSex);
    }

    public String getStatus_Id()
    {
        return Status_Id;
    }

    public void setStatus_Id(String aStatus_Id)
    {
        Status_Id = StrTool.cTrim(aStatus_Id);
    }

    public String getTel()
    {
        return Tel;
    }

    public void setTel(String aTel)
    {
        Tel = StrTool.cTrim(aTel);
    }

    public String getCreate_Date()
    {
        if (Create_Date == null)
            return null;
        else
            return fDate.getString(Create_Date);
    }

    public void setCreate_Date(Date aCreate_Date)
    {
        Create_Date = aCreate_Date;
    }

    public void setCreate_Date(String aCreate_Date)
    {
        if (aCreate_Date == null || aCreate_Date.equals(""))
            Create_Date = null;
        else
            Create_Date = fDate.getDate(aCreate_Date);
    }

    public String getInsert_Time()
    {
        if (Insert_Time == null)
            return null;
        else
            return fDate.getString(Insert_Time);
    }

    public void setInsert_Time(Date aInsert_Time)
    {
        Insert_Time = aInsert_Time;
    }

    public void setInsert_Time(String aInsert_Time)
    {
        if (aInsert_Time == null || aInsert_Time.equals(""))
            Insert_Time = null;
        else
            Insert_Time = fDate.getDate(aInsert_Time);
    }

    public String getUpdate_Time()
    {
        if (Update_Time == null)
            return null;
        else
            return fDate.getString(Update_Time);
    }

    public void setUpdate_Time(Date aUpdate_Time)
    {
        Update_Time = aUpdate_Time;
    }

    public void setUpdate_Time(String aUpdate_Time)
    {
        if (aUpdate_Time == null || aUpdate_Time.equals(""))
            Update_Time = null;
        else
            Update_Time = fDate.getDate(aUpdate_Time);
    }

    public String getOperator()
    {
        return Operator;
    }

    public void setOperator(String aOperator)
    {
        Operator = StrTool.cTrim(aOperator);
    }


    /**
     * 使用另外一个 T_UserSchema 对象给 Schema 赋值
     * @param: cT_UserSchema T_UserSchema
     */
    public void setSchema(T_UserSchema cT_UserSchema)
    {
        this.User_Code = cT_UserSchema.getUser_Code();
        this.Organ_Id = cT_UserSchema.getOrgan_Id();
        this.PassWord = cT_UserSchema.getPassWord();
        this.Real_Name = cT_UserSchema.getReal_Name();
        this.Type_Id = cT_UserSchema.getType_Id();
        this.Sex = cT_UserSchema.getSex();
        this.Status_Id = cT_UserSchema.getStatus_Id();
        this.Tel = cT_UserSchema.getTel();
        this.Create_Date = fDate.getDate(cT_UserSchema.getCreate_Date());
        this.Insert_Time = fDate.getDate(cT_UserSchema.getInsert_Time());
        this.Update_Time = fDate.getDate(cT_UserSchema.getUpdate_Time());
        this.Operator = cT_UserSchema.getOperator();
    }

    /**
     * 使用 ResultSet 中的第 i 行给 Schema 赋值
     * @param: rs ResultSet
     * @param: i int
     * @return: boolean
     */
    public boolean setSchema(ResultSet rs, int i)
    {
        try
        {
            if (rs.getString(1) == null)
                this.User_Code = null;
            else
                this.User_Code = rs.getString(1);
            if (rs.getString(2) == null)
                this.Organ_Id = null;
            else
                this.Organ_Id = rs.getString(2);
            if (rs.getString(3) == null)
                this.PassWord = null;
            else
                this.PassWord = rs.getString(3);
            if (rs.getString(4) == null)
                this.Real_Name = null;
            else
                this.Real_Name = rs.getString(4);
            if (rs.getString(5) == null)
                this.Type_Id = null;
            else
                this.Type_Id = rs.getString(5);
            if (rs.getString(6) == null)
                this.Sex = null;
            else
                this.Sex = rs.getString(6);
            if (rs.getString(7) == null)
                this.Status_Id = null;
            else
                this.Status_Id = rs.getString(7);
            if (rs.getString(8) == null)
                this.Tel = null;
            else
                this.Tel = rs.getString(8);
            this.Create_Date = rs.getDate(9);
            this.Insert_Time = rs.getDate(10);
            this.Update_Time = rs.getDate(11);
            if (rs.getString(12) == null)
                this.Operator = null;
            else
                this.Operator = rs.getString(12);
        }
        catch (SQLException sqle)
        {
            sqle.printStackTrace();
            // @@错误处理
            CError tError = new CError();
            tError.moduleName = "T_UserSchema";
            tError.functionName = "setSchema";
            tError.errorMessage = sqle.toString();
            this.mErrors.addOneError(tError);
            return false;
        }
        return true;
    }

    public T_UserSchema getSchema()
    {
        T_UserSchema aT_UserSchema = new T_UserSchema();
        aT_UserSchema.setSchema(this);
        return aT_UserSchema;
    }

    public T_UserDB getDB()
    {
        T_UserDB aDBOper = new T_UserDB();
        aDBOper.setSchema(this);
        return aDBOper;
    }

    /**
     * 数据打包，按 XML 格式打包
     * @return: String 返回打包后字符串
     */
    public String encode()
    {
        StringBuffer strReturn = new StringBuffer(256);
        strReturn.append(StrTool.cTrim(User_Code));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(Organ_Id));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(PassWord));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(Real_Name));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(Type_Id));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(Sex));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(Status_Id));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(Tel));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(fDate.getString(Create_Date)));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(fDate.getString(Insert_Time)));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(fDate.getString(Update_Time)));
        strReturn.append(SysConst.PACKAGESPILTER);
        strReturn.append(StrTool.cTrim(Operator));
        return strReturn.toString();
    }

    /**
     * 数据解包
     * @param: strMessage String 包含一条纪录数据的字符串
     * @return: boolean
     */
    public boolean decode(String strMessage)
    {
        try
        {
            User_Code = StrTool.getStr(strMessage, 1, SysConst.PACKAGESPILTER);
            Organ_Id = StrTool.getStr(strMessage, 2, SysConst.PACKAGESPILTER);
            PassWord = StrTool.getStr(strMessage, 3, SysConst.PACKAGESPILTER);
            Real_Name = StrTool.getStr(strMessage, 4, SysConst.PACKAGESPILTER);
            Type_Id = StrTool.getStr(strMessage, 5, SysConst.PACKAGESPILTER);
            Sex = StrTool.getStr(strMessage, 6, SysConst.PACKAGESPILTER);
            Status_Id = StrTool.getStr(strMessage, 7, SysConst.PACKAGESPILTER);
            Tel = StrTool.getStr(strMessage, 8, SysConst.PACKAGESPILTER);
            Create_Date = fDate.getDate(StrTool.getStr(strMessage, 9, SysConst.PACKAGESPILTER));
            Insert_Time = fDate.getDate(StrTool.getStr(strMessage, 10, SysConst.PACKAGESPILTER));
            Update_Time = fDate.getDate(StrTool.getStr(strMessage, 11, SysConst.PACKAGESPILTER));
            Operator = StrTool.getStr(strMessage, 12, SysConst.PACKAGESPILTER);
        }
        catch (NumberFormatException ex)
        {
            // @@错误处理
            CError tError = new CError();
            tError.moduleName = "T_UserSchema";
            tError.functionName = "decode";
            tError.errorMessage = ex.toString();
            this.mErrors.addOneError(tError);
            return false;
        }
        return true;
    }

    /**
     * 取得对应传入参数的String形式的字段值
     * @param: FCode String 希望取得的字段名
     * @return: String
     * 如果没有对应的字段，返回""
     * 如果字段值为空，返回"null"
     */
    public String getV(String FCode)
    {
        String strReturn = "";
        if (FCode.equalsIgnoreCase("User_Code"))
        {
            strReturn = StrTool.cTrim(User_Code);
        }
        if (FCode.equalsIgnoreCase("Organ_Id"))
        {
            strReturn = StrTool.cTrim(Organ_Id);
        }
        if (FCode.equalsIgnoreCase("PassWord"))
        {
            strReturn = StrTool.cTrim(PassWord);
        }
        if (FCode.equalsIgnoreCase("Real_Name"))
        {
            strReturn = StrTool.cTrim(Real_Name);
        }
        if (FCode.equalsIgnoreCase("Type_Id"))
        {
            strReturn = StrTool.cTrim(Type_Id);
        }
        if (FCode.equalsIgnoreCase("Sex"))
        {
            strReturn = StrTool.cTrim(Sex);
        }
        if (FCode.equalsIgnoreCase("Status_Id"))
        {
            strReturn = StrTool.cTrim(Status_Id);
        }
        if (FCode.equalsIgnoreCase("Tel"))
        {
            strReturn = StrTool.cTrim(Tel);
        }
        if (FCode.equalsIgnoreCase("Create_Date"))
        {
            strReturn = StrTool.cTrim(this.getCreate_Date());
        }
        if (FCode.equalsIgnoreCase("Insert_Time"))
        {
            strReturn = StrTool.cTrim(this.getInsert_Time());
        }
        if (FCode.equalsIgnoreCase("Update_Time"))
        {
            strReturn = StrTool.cTrim(this.getUpdate_Time());
        }
        if (FCode.equalsIgnoreCase("Operator"))
        {
            strReturn = StrTool.cTrim(Operator);
        }
        if (strReturn.equals(""))
        {
            strReturn = "null";
        }
        return strReturn;
    }

    /**
     * 取得Schema中指定索引值所对应的字段值
     * @param: nFieldIndex int 指定的字段索引值
     * @return: String
     * 如果没有对应的字段，返回""
     * 如果字段值为空，返回"null"
     */
    public String getV(int nFieldIndex)
    {
        String strFieldValue = "";
        switch (nFieldIndex)
        {
            case 0:
                strFieldValue = StrTool.cTrim(User_Code);
                break;
            case 1:
                strFieldValue = StrTool.cTrim(Organ_Id);
                break;
            case 2:
                strFieldValue = StrTool.cTrim(PassWord);
                break;
            case 3:
                strFieldValue = StrTool.cTrim(Real_Name);
                break;
            case 4:
                strFieldValue = StrTool.cTrim(Type_Id);
                break;
            case 5:
                strFieldValue = StrTool.cTrim(Sex);
                break;
            case 6:
                strFieldValue = StrTool.cTrim(Status_Id);
                break;
            case 7:
                strFieldValue = StrTool.cTrim(Tel);
                break;
            case 8:
                strFieldValue = StrTool.cTrim(this.getCreate_Date());
                break;
            case 9:
                strFieldValue = StrTool.cTrim(this.getInsert_Time());
                break;
            case 10:
                strFieldValue = StrTool.cTrim(this.getUpdate_Time());
                break;
            case 11:
                strFieldValue = StrTool.cTrim(Operator);
                break;
            default:
                strFieldValue = "";
        }
        if (strFieldValue.equals(""))
        {
            strFieldValue = "null";
        }
        return strFieldValue;
    }

    /**
     * 设置对应传入参数的String形式的字段值
     * @param: FCode String 需要赋值的对象
     * @param: FValue String 要赋的值
     * @return: boolean
     */
    public boolean setV(String FCode, String FValue)
    {
        if (StrTool.cTrim(FCode).equals(""))
            return false;

        if (FCode.equalsIgnoreCase("User_Code"))
        {
            if (FValue != null)
            {
                User_Code = FValue.trim();
            }
            else
                User_Code = null;
        }
        if (FCode.equalsIgnoreCase("Organ_Id"))
        {
            if (FValue != null)
            {
                Organ_Id = FValue.trim();
            }
            else
                Organ_Id = null;
        }
        if (FCode.equalsIgnoreCase("PassWord"))
        {
            if (FValue != null)
            {
                PassWord = FValue.trim();
            }
            else
                PassWord = null;
        }
        if (FCode.equalsIgnoreCase("Real_Name"))
        {
            if (FValue != null)
            {
                Real_Name = FValue.trim();
            }
            else
                Real_Name = null;
        }
        if (FCode.equalsIgnoreCase("Type_Id"))
        {
            if (FValue != null)
            {
                Type_Id = FValue.trim();
            }
            else
                Type_Id = null;
        }
        if (FCode.equalsIgnoreCase("Sex"))
        {
            if (FValue != null)
            {
                Sex = FValue.trim();
            }
            else
                Sex = null;
        }
        if (FCode.equalsIgnoreCase("Status_Id"))
        {
            if (FValue != null)
            {
                Status_Id = FValue.trim();
            }
            else
                Status_Id = null;
        }
        if (FCode.equalsIgnoreCase("Tel"))
        {
            if (FValue != null)
            {
                Tel = FValue.trim();
            }
            else
                Tel = null;
        }
        if (FCode.equalsIgnoreCase("Create_Date"))
        {
            if (FValue != null)
            {
                Create_Date = fDate.getDate(FValue);
            }
            else
                Create_Date = null;
        }
        if (FCode.equalsIgnoreCase("Insert_Time"))
        {
            if (FValue != null)
            {
                Insert_Time = fDate.getDate(FValue);
            }
            else
                Insert_Time = null;
        }
        if (FCode.equalsIgnoreCase("Update_Time"))
        {
            if (FValue != null)
            {
                Update_Time = fDate.getDate(FValue);
            }
            else
                Update_Time = null;
        }
        if (FCode.equalsIgnoreCase("Operator"))
        {
            if (FValue != null)
            {
                Operator = FValue.trim();
            }
            else
                Operator = null;
        }
        return true;
    }

    public boolean equals(Object otherObject)
    {
        if (this == otherObject)
            return true;
        if (otherObject == null)
            return false;
        if (getClass() != otherObject.getClass())
            return false;
        T_UserSchema other = (T_UserSchema) otherObject;
        return
                (User_Code == null ? other.getUser_Code() == null : User_Code.equals(other.getUser_Code()))
                && (Organ_Id == null ? other.getOrgan_Id() == null : Organ_Id.equals(other.getOrgan_Id()))
                && (PassWord == null ? other.getPassWord() == null : PassWord.equals(other.getPassWord()))
                && (Real_Name == null ? other.getReal_Name() == null : Real_Name.equals(other.getReal_Name()))
                && (Type_Id == null ? other.getType_Id() == null : Type_Id.equals(other.getType_Id()))
                && (Sex == null ? other.getSex() == null : Sex.equals(other.getSex()))
                && (Status_Id == null ? other.getStatus_Id() == null : Status_Id.equals(other.getStatus_Id()))
                && (Tel == null ? other.getTel() == null : Tel.equals(other.getTel()))
                && (Create_Date == null ? other.getCreate_Date() == null : fDate.getString(Create_Date).equals(other.getCreate_Date()))
                && (Insert_Time == null ? other.getInsert_Time() == null : fDate.getString(Insert_Time).equals(other.getInsert_Time()))
                && (Update_Time == null ? other.getUpdate_Time() == null : fDate.getString(Update_Time).equals(other.getUpdate_Time()))
                && (Operator == null ? other.getOperator() == null : Operator.equals(other.getOperator()));
    }

    /**
     * 取得Schema拥有字段的数量
     * @return: int
     */
    public int getFieldCount()
    {
        return FIELDNUM;
    }

    /**
     * 取得Schema中指定字段名所对应的索引值
     * 如果没有对应的字段，返回-1
     * @param: strFieldName String
     * @return: int
     */
    public int getFieldIndex(String strFieldName)
    {
        if (strFieldName.equals("User_Code"))
        {
            return 0;
        }
        if (strFieldName.equals("Organ_Id"))
        {
            return 1;
        }
        if (strFieldName.equals("PassWord"))
        {
            return 2;
        }
        if (strFieldName.equals("Real_Name"))
        {
            return 3;
        }
        if (strFieldName.equals("Type_Id"))
        {
            return 4;
        }
        if (strFieldName.equals("Sex"))
        {
            return 5;
        }
        if (strFieldName.equals("Status_Id"))
        {
            return 6;
        }
        if (strFieldName.equals("Tel"))
        {
            return 7;
        }
        if (strFieldName.equals("Create_Date"))
        {
            return 8;
        }
        if (strFieldName.equals("Insert_Time"))
        {
            return 9;
        }
        if (strFieldName.equals("Update_Time"))
        {
            return 10;
        }
        if (strFieldName.equals("Operator"))
        {
            return 11;
        }
        return -1;
    }

    /**
     * 取得Schema中指定索引值所对应的字段名
     * 如果没有对应的字段，返回""
     * @param: nFieldIndex int
     * @return: String
     */
    public String getFieldName(int nFieldIndex)
    {
        String strFieldName = "";
        switch (nFieldIndex)
        {
            case 0:
                strFieldName = "User_Code";
                break;
            case 1:
                strFieldName = "Organ_Id";
                break;
            case 2:
                strFieldName = "PassWord";
                break;
            case 3:
                strFieldName = "Real_Name";
                break;
            case 4:
                strFieldName = "Type_Id";
                break;
            case 5:
                strFieldName = "Sex";
                break;
            case 6:
                strFieldName = "Status_Id";
                break;
            case 7:
                strFieldName = "Tel";
                break;
            case 8:
                strFieldName = "Create_Date";
                break;
            case 9:
                strFieldName = "Insert_Time";
                break;
            case 10:
                strFieldName = "Update_Time";
                break;
            case 11:
                strFieldName = "Operator";
                break;
            default:
                strFieldName = "";
        }
        return strFieldName;
    }

    /**
     * 取得Schema中指定字段名所对应的字段类型
     * 如果没有对应的字段，返回Schema.TYPE_NOFOUND
     * @param: strFieldName String
     * @return: int
     */
    public int getFieldType(String strFieldName)
    {
        if (strFieldName.equals("User_Code"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("Organ_Id"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("PassWord"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("Real_Name"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("Type_Id"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("Sex"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("Status_Id"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("Tel"))
        {
            return Schema.TYPE_STRING;
        }
        if (strFieldName.equals("Create_Date"))
        {
            return Schema.TYPE_DATE;
        }
        if (strFieldName.equals("Insert_Time"))
        {
            return Schema.TYPE_DATE;
        }
        if (strFieldName.equals("Update_Time"))
        {
            return Schema.TYPE_DATE;
        }
        if (strFieldName.equals("Operator"))
        {
            return Schema.TYPE_STRING;
        }
        return Schema.TYPE_NOFOUND;
    }

    /**
     * 取得Schema中指定索引值所对应的字段类型
     * 如果没有对应的字段，返回Schema.TYPE_NOFOUND
     * @param: nFieldIndex int
     * @return: int
     */
    public int getFieldType(int nFieldIndex)
    {
        int nFieldType = Schema.TYPE_NOFOUND;
        switch (nFieldIndex)
        {
            case 0:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 1:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 2:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 3:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 4:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 5:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 6:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 7:
                nFieldType = Schema.TYPE_STRING;
                break;
            case 8:
                nFieldType = Schema.TYPE_DATE;
                break;
            case 9:
                nFieldType = Schema.TYPE_DATE;
                break;
            case 10:
                nFieldType = Schema.TYPE_DATE;
                break;
            case 11:
                nFieldType = Schema.TYPE_STRING;
                break;
            default:
                nFieldType = Schema.TYPE_NOFOUND;
        }
        return nFieldType;
    }
}
